package cn.bdqn.pn.controller.commodity;
import cn.bdqn.pn.pojo.base.Img;
import cn.bdqn.pn.pojo.commodity.Commodity;
import cn.bdqn.pn.pojo.commodity.Sku;
import cn.bdqn.pn.pojo.commodity.Ticketinginfo;
import cn.bdqn.pn.pojo.commodity.params.CommodityParams;
import cn.bdqn.pn.pojo.schedule.Commoditysession;
import cn.bdqn.pn.pojo.schedule.Place;
import cn.bdqn.pn.pojo.user.Admin;
import cn.bdqn.pn.service.base.CityService;
import cn.bdqn.pn.service.base.ImgService;
import cn.bdqn.pn.service.commodity.CommodityService;
import cn.bdqn.pn.service.commodity.CommodityServiceImpl.SkuServiceImpl;
import cn.bdqn.pn.service.commodity.CommodityServiceImpl.TicketinginfoServiceImpl;
import cn.bdqn.pn.service.commodity.ShowTypeService;
import cn.bdqn.pn.service.schedule.CommoditysessionService;
import cn.bdqn.pn.service.schedule.PlaceService;
import cn.bdqn.pn.utils.FastDFSClient;
import com.alibaba.fastjson.JSON;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;


@Controller
@RequestMapping("/commodityController")
public class CommodityController {

    @Autowired
    CommodityService commodityService;
    @Autowired
    TicketinginfoServiceImpl ticketinginfoService;


    @Autowired
    SkuServiceImpl skuService;

    @Autowired
    ImgService imgService;

    @Autowired
    PlaceService placeService;

    @Autowired
    CityService cityService;

    @Autowired
    CommoditysessionService CommoditysessionService;

    @Autowired
    ShowTypeService showTypeService;

    /**
     * ------------cp
     * 添加商品跳转地址
     * @return
     */
    @RequestMapping("/addCommodity")
    public String addCommodity(){
        return "add_Article";
    }


    /**
     * -----------cp
     * 查询商品信息
     * @param model
     * @param commodity
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping("/info")
    public String info(Model model,Commodity commodity,@Param("pageNo") Integer pageNo,@Param("size") Integer pageSize){


        System.out.println("我好想睡觉睡觉++++++++++++++++++++++++++++++++++++++++++++++Are You Understand?");

        String shopName=commodity.getCommodityName();
        Integer shopStatus=commodity.getStatus();
        Integer isBoolSeat=commodity.getIsSeat();
        Integer providerId=commodity.getProvinceId();
        Integer cityId=commodity.getCityId();
        Integer fatherTypeId=commodity.getTypeId();
        Integer childTypeId=commodity.getClildTypeId();
        String  startTime=commodity.getStartTime();
        String  endTime=commodity.getEndTime();
        Integer starLever=commodity.getStar();

        System.out.println(pageNo+"  pageNo");
        System.out.println(pageSize+"  pageSize");
        System.out.println(shopName+"  shopName");
        System.out.println(shopStatus+"  shopStatus");
        System.out.println(isBoolSeat+"  isBoolSeat");
        System.out.println(providerId+"  providerId");
        System.out.println(cityId+"  cityId");
        System.out.println(fatherTypeId+"  fatherTypeId");
        System.out.println(childTypeId+"  childTypeId");
        System.out.println(startTime+"  startTime");
        System.out.println(endTime+"  endTime");
        System.out.println(starLever+"  starLever");



        Page<Commodity> commodityPage=null;
        try {
            commodityPage=commodityService.getCommodityInfoByPage(commodity,pageNo,pageSize);
            System.out.println("----                   ++++++++++++++++++++++++++++++++++++");

           /* System.out.println("cdy         "+JSON.toJSONString(commodityPage));*/
          //  System.out.println("cdy         "+JSON.toJSONString(commodityPage));
            List<Commodity> list=commodityPage.getContent();
            for(Commodity com:list){

                Integer cityId2=com.getCityId();
                Integer typeId=com.getTypeId();
                //根据城市编号查询城市城市名称
                String cityName=cityService.findCityBycityId(cityId2).getCityName();
                //根据类别Id查询类别名称
                String fatherName=showTypeService.findShowTypeById(typeId).getTypeName();
                com.setCityName(cityName);
                com.setTypeName(fatherName);

            }
            System.out.println("----                   ++++++++++++++++++++++++++++++++++++");
        }catch (Exception e){
            e.printStackTrace();
        }

        model.addAttribute("page",commodityPage);
        model.addAttribute("shopName",shopName);
        model.addAttribute("shopStatus",shopStatus);
        model.addAttribute("isBoolSeat",isBoolSeat);
        model.addAttribute("providerId",providerId);
        model.addAttribute("cityId",cityId);
        model.addAttribute("fatherTypeId",fatherTypeId);
        model.addAttribute("childTypeId",childTypeId);
        model.addAttribute("startTime",startTime);
        model.addAttribute("endTime",endTime);
        model.addAttribute("starLever",starLever);

        return "Products1";
    }


    /**
     * ----------------cp
     * 修改商品状态
     * @param commodityId
     * @return
     * 更改上下架状态
     */
    @ResponseBody
    @RequestMapping("/updateShopStatus")
    public boolean updateShopStatus(@Param("commodityId") Integer commodityId,@Param("status")Integer status){

        boolean bb=commodityService.updateCommodityStatus(commodityId,status);
        return bb;
    }








    /**
     * 条件分页查询-------------------------------------------------可能删除
     * @param commodityParams
     * @param page
     * @param size
     * @return
     */
    @ResponseBody
    @RequestMapping("/testPage")
    public String getCommodityByPage(CommodityParams commodityParams,@Param("page") Integer page,@Param("size") Integer size)  {
        if (commodityParams.getStartTime()!=null && !commodityParams.getStartTime().equals("") && commodityParams.getEndTime()!=null && !commodityParams.getEndTime().equals("")){
           /* try {
                SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
                String startTime = sdf.format(commodityParams.getStartTime());  //2015-02-09  format()才是格式化
                String endTime = sdf.format(commodityParams.getEndTime());  //2015-02-09  format()才是格式化
                Date startTime1 = null;
                startTime1 = sdf.parse(startTime);
                Date endTime1 = null;
                endTime1 = sdf.parse(endTime);

                System.out.println(commodityParams.getStartTime()+"++++++"+commodityParams.getEndTime());
                System.out.println(startTime1+"--------------"+endTime1);
            }catch (Exception e){
                e.printStackTrace();
            }*/
        }
        commodityParams.setStatus(commodityParams.getStatus()-1);
        commodityParams.setIsDel(1);//查询存在的
        Page<Commodity> commodityPage=commodityService.findAllCommodity(commodityParams,page,size);
        //System.out.println(JSON.toJSONString(commodityPage,true));
        return JSON.toJSONString(commodityPage,true);
    }












    /**
     * ---------------cp
     * 删除商品信息，同时删除SKU中商品编号的sku
     */
    @ResponseBody
    @RequestMapping("/deteleCommodity")
    public Integer deteleCommodity(@RequestParam("commodityId") Integer commodityId){
        System.out.println(commodityId+"删除的id");
        boolean flag= commodityService.updateCommodity(commodityId);
        List<Sku> skuList= skuService.getSkuListByCommodityId(commodityId);

        for(Sku sku:skuList){
            //循环更新商品编号为sku.getCommdityId()的sku
            System.out.println(sku.getSkuId()+"        ++++++++++");
            flag=skuService.updateSkuStatus(sku.getSkuId());
        }

        if (flag){
            return 1;
        }else{
            return 2;
        }
    }




    /**
     * ---------------------cp
     * 点击添加商品时候调用
     *处理商品基本信息和票档说明
     * 也就是新增商品和购票限制说明
     */

    @RequestMapping(value = "/MultPictareaddData")
    @ResponseBody
    public String MultPictareaddData(@RequestParam("file") MultipartFile[] files,
                                     @RequestParam(value = "shouhuoTime",required = false) String shouhuoTime,
                                     @RequestParam(value = "getPickAddress2",required = false) String getPickAddress2,
                                     @RequestParam("str") String str,
                                     @RequestParam("shopProvider") String shopProvider,

                                     @RequestParam("shopName") String shopName,
                                     @RequestParam("typeId") Integer typeId,
                                     @RequestParam("smallTypeList") Integer smallTypeList,
                                     @RequestParam("maxCount") Integer maxCount,

                                     @RequestParam("isBoolSeat") Integer isBoolSeat,
                                     @RequestParam("shopStartTime") String shopStartTime,
                                     @RequestParam("shopEndTime") String shopEndTime,
                                     @RequestParam("bianjiqi") String bianjiqi,

                                     @RequestParam("xianGou") String xianGou,
                                     @RequestParam("seatType") String seatType,
                                     @RequestParam("childInfo") String childInfo,
                                     @RequestParam("entityTicket") String entityTicket,

                                     @RequestParam("Eticket") String Eticket,
                                     @RequestParam("jinZiInfo") String jinZiInfo,
                                     @RequestParam("Trestriction") String Trestriction,
                                     @RequestParam("elseInfo") String elseInfo,

                                     HttpServletRequest request) throws IOException, SQLException {
        String imgPath="";

        //购票须知Id
        Integer tickerId;
        //省级Id
        Integer providerId=0;
        //市级Id
        Integer shiJi=0;

        String result="";

        if(files!=null && files.length>0){
            System.out.println("====================="+files.length+"=====================");
            for(int i=0;i<files.length;i++){
                MultipartFile file=files[i];
                //保存图片
                //imgPath+=saveFile(request,file)+(i<files.length-1?"*":"");
                imgPath= FastDFSClient.saveFile(file);
                System.out.println(imgPath+"========================  imgPaths");
            }


            //1 新增购票须知，返回主键Id
            Ticketinginfo tickXuZhi=new Ticketinginfo();
            tickXuZhi.setBuyAmountExplain(xianGou);
            tickXuZhi.setChildrenEntranceHint(childInfo);
            tickXuZhi.setElectronicTicket(Eticket);
            tickXuZhi.setEntityTicket(entityTicket);
            tickXuZhi.setOtherExplain(elseInfo);
            tickXuZhi.setProhibitedArticles(jinZiInfo);
            tickXuZhi.setSeatType(seatType);
            tickXuZhi.setTicketRestrictions(Trestriction);
            boolean bb=ticketinginfoService.addTicketinginfo(tickXuZhi);

            //新增购票须知成功
            if(bb){
                tickerId=tickXuZhi.getTicketInfoId();

                //根据登录的代理商Id，查询省，市级代理商id
                //这里供应商ID暂定为3,合在一起后再获取-------------------------------------------------------------

                Admin admin=(Admin)request.getSession().getAttribute("admin");
                List<Place> placeList=placeService.findByagentId(admin.getAdminId());
                //获取代理商的省级和市级编号
                for(Place pp:placeList){
                    providerId=pp.getCityoneId();
                    shiJi=pp.getCitytwoId();
                    break;
                }

                // 新增商品

                Commodity commodity=new Commodity();

                commodity.setLogistics(str);//物流
                commodity.setSupplierName(shopProvider);//供应商
                commodity.setSouHuoTimeInfo(shouhuoTime);
                commodity.setShouHuoAddress(getPickAddress2);

                commodity.setTypeId(typeId);
                commodity.setClildTypeId(smallTypeList);
                commodity.setProvinceId(providerId);
                commodity.setCityId(shiJi);
                commodity.setCommodityName(shopName);
                commodity.setStartTime(shopStartTime);
                commodity.setEndTime(shopEndTime);
                System.out.println("------------------------------->>>>>>>  "+imgPath);
                //String imgUrl=(String)request.getSession().getAttribute("imgUrl");
                //System.out.println(imgUrl+"          图片+++路径");
                commodity.setImgURL(imgPath);
                commodity.setStar(1);//级别 为   1-5    ，   默认为1
                commodity.setStatus(1);//新增商品状态默认为上架，1
                commodity.setPutDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                commodity.setIsSeat(isBoolSeat);
                commodity.setBuyAmount(maxCount);
                commodity.setCommodityDetails(bianjiqi);//这里为百度编辑器获取的内容
                commodity.setIsDel(1);//默认不删除，1不删除，2删除
                commodity.setTicketInfoId(tickerId);//购票须知Id
                Commodity cc=commodityService.addCommodity(commodity);
                //新增商品成功
                if(cc!=null){
                    HttpSession session=request.getSession();//创建session对象
                    session.setAttribute("shopId",cc.getCommodityId());//新增商品，将商品Id保存在session中


                    //向图片表中插入数据
                    System.out.println("================="+imgPath);
                    //将图片保存到数据库中
                    Img img=new Img();
                    img.setImgtypeid(6);//这里定死了，商品的为6
                    img.setImgurl(imgPath);
                    img.setReleid(cc.getCommodityId());//商品Id
                    boolean falg=imgService.addImgInfo(img);
                    if(falg){
                        result="true";
                    }else{
                        result="false";

                    }
                }else{
                    result="false";
                }

            }else{
                result="false";
            }

        }else{
            System.out.println(files.length+"========================");
            result="exception";

        }
        return JSON.toJSONString(result);
    }

    private String saveFile(HttpServletRequest request,MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        String name = file.getName();
        String randomUUID = UUID.randomUUID().toString();
        int index = originalFilename.lastIndexOf(".");
        String exet = originalFilename.substring(index);
        Date date = new Date();
        //SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd\\HH\\mm\\ss");
        //String dateStr = sdf.format(date); // D:\\uploads\\20180824 String
        String filePath = "E:\\pn\\pnImage\\";
        System.out.println("filePath=" + filePath);
        File file2 = new File(filePath);
        if (!file2.exists()) {
            file2.mkdirs();
        }
        //经过转换后的图片名称
        String imgPath=randomUUID+exet;
        System.out.println("图片名="+imgPath);
        filePath += "\\" + randomUUID + exet;

        request.getSession().setAttribute("imgUrl",filePath);
        System.out.println(filePath);
        file.transferTo(new File(filePath));// ctrl+1
        return imgPath;
    }



    /**
     * ---------------------cp
     * 点击更新商品时候调用
     *处理商品基本信息和票档说明
     * 也就是更新商品和购票限制说明
     */

    @RequestMapping(value = "/updateShopInfo")//检查发现毛病，必须要更改图片
    @ResponseBody
    public String updateShopInfo(@RequestParam("file") MultipartFile[] files,
                                     @RequestParam(value = "shopId") Integer shopId,
                                     @RequestParam(value = "ticketInfoId") Integer ticketInfoId,
                                     @RequestParam(value = "shouhuoTime",required = false) String shouhuoTime,
                                     @RequestParam(value = "getPickAddress2",required = false) String getPickAddress2,
                                     @RequestParam("str") String str,
                                     @RequestParam("shopProvider") String shopProvider,

                                     @RequestParam("shopName") String shopName,
                                     @RequestParam("typeId") Integer typeId,
                                     @RequestParam("smallTypeList") Integer smallTypeList,
                                     @RequestParam("maxCount") Integer maxCount,

                                     @RequestParam("isBoolSeat") Integer isBoolSeat,
                                     @RequestParam("shopStartTime") String shopStartTime,
                                     @RequestParam("shopEndTime") String shopEndTime,
                                     @RequestParam("bianjiqi") String bianjiqi,

                                     @RequestParam("xianGou") String xianGou,
                                     @RequestParam("seatType") String seatType,
                                     @RequestParam("childInfo") String childInfo,
                                     @RequestParam("entityTicket") String entityTicket,

                                     @RequestParam("Eticket") String Eticket,
                                     @RequestParam("jinZiInfo") String jinZiInfo,
                                     @RequestParam("Trestriction") String Trestriction,
                                     @RequestParam("elseInfo") String elseInfo,

                                     HttpServletRequest request) throws IOException, SQLException {
        String imgPath="";
        String result="";

        if(files!=null && files.length>0){
            System.out.println("====================="+files.length+"=====================");
            for(int i=0;i<files.length;i++){
                MultipartFile file=files[i];
                //保存图片
               // imgPath+=saveFile(request,file)+(i<files.length-1?"*":"");
                imgPath= FastDFSClient.saveFile(file);
            }


            //1 修改购票须知，通过购票须知Id获取购票信息
            Ticketinginfo tickXuZhi=ticketinginfoService.getTicketinginfoByTicketInfoId(ticketInfoId);
            tickXuZhi.setBuyAmountExplain(xianGou);
            tickXuZhi.setChildrenEntranceHint(childInfo);
            tickXuZhi.setElectronicTicket(Eticket);
            tickXuZhi.setEntityTicket(entityTicket);
            tickXuZhi.setOtherExplain(elseInfo);
            tickXuZhi.setProhibitedArticles(jinZiInfo);
            tickXuZhi.setSeatType(seatType);
            tickXuZhi.setTicketRestrictions(Trestriction);
            boolean bb=ticketinginfoService.addTicketinginfo(tickXuZhi);

            //修改购票须知成功
            if(bb){

                // 根据商品Id获取商品
                Commodity commodity=commodityService.getCommodityById(shopId);
                commodity.setLogistics(str);//物流
                commodity.setSupplierName(shopProvider);//供应商
                commodity.setSouHuoTimeInfo(shouhuoTime);
                commodity.setShouHuoAddress(getPickAddress2);

                commodity.setTypeId(typeId);
                commodity.setClildTypeId(smallTypeList);

                commodity.setCommodityName(shopName);
                commodity.setStartTime(shopStartTime);
                commodity.setEndTime(shopEndTime);
                commodity.setImgURL(imgPath);
                commodity.setIsSeat(isBoolSeat);
                commodity.setBuyAmount(maxCount);
                commodity.setCommodityDetails(bianjiqi);//这里为百度编辑器获取的内容
                Commodity cc=commodityService.addCommodity(commodity);//修改商品信息
                //修改商品成功
                if(cc!=null){

                   //这里正确的思路应该是 通过商品Id获取图片信息，
                   // 然后在更新
                    //将图片保存到数据库中
                    Img img=imgService.findImgByReleidAndImgtypeid(shopId,6);
                    img.setImgurl(imgPath);

                    boolean falg=imgService.addImgInfo(img);
                    if(falg){
                        result="true";
                    }else{
                        result="false";

                    }
                }else{
                    result="false";
                }

            }else{
                result="false";
            }

        }else{
            System.out.println(files.length+"========================");
            result="exception";

        }
        return JSON.toJSONString(result);
    }





    /**
     * ---------------cp
     *添加场次信息
     * @return
     */
    @RequestMapping(value = "/addChangCi")
    @ResponseBody
    public Object addChangCi(String str){
        Map<String,Object> hMap=new HashMap<>();
        List<Commoditysession> comSessList=new ArrayList<>();

        /*       xx*2019-08-06 15:13:25*2019-08-07 15:13:29*0,ff*2019-08-08 15:13:31*2019-08-09 15:13:35*0            */
        //截取字符串
        //以,分割
        //以/分开
        boolean bb=false;
        Commoditysession cSess=null;
        String [] arrs=str.split(",");
        String [] changCi=null;
        for(int i=0;i<arrs.length;i++){
            System.out.println(arrs[i]);
            cSess=new Commoditysession();
            changCi=arrs[i].split("/");
            cSess.setSessiontime(changCi[0]);
            cSess.setStarttime(changCi[1]);
            cSess.setEndtime(changCi[2]);
            cSess.setStatus(1);
            cSess.setPlaceId(Integer.parseInt(changCi[3]));
            Commoditysession cc=CommoditysessionService.addCommoditysession(cSess);
            if(cc!=null){
                bb=true;
                comSessList.add(cc);
            }


        }
        hMap.put("res",bb);
        hMap.put("ccList",comSessList);
        return  hMap;

    }

    /**
     * ---------cp
     * 添加sku信息
     * @param changCiId
     * @param piaoDangId
     * @param price
     * @param isBoolDis
     * @param discount
     * @return
     */
    @ResponseBody
    @RequestMapping("/addSku")
    public String addSku(
                          @RequestParam("changCiId") Integer changCiId,
                          @RequestParam("piaoDangId") Integer piaoDangId,
                          @RequestParam("price") Double price,
                          @RequestParam("isBoolDis") Integer isBoolDis,
                          @RequestParam("discount") Double discount
                          ){
        //封装sku类
        Sku  sku=new Sku();
        sku.setSessionId(changCiId);
        sku.setTicketFileId(piaoDangId);
        sku.setPrice(price);
        sku.setIsDis(isBoolDis);
        sku.setDiscount(discount);
        sku.setSkuStatus(1);
        //商品Id从session中获取，那边我在新增商品后，将商品ID放在Session中
        HttpServletRequest request =
                ((ServletRequestAttributes) RequestContextHolder.
                        getRequestAttributes()).getRequest();
        HttpSession session=request.getSession();//创建session对象
        Integer shopId=(Integer) session.getAttribute("shopId");
        System.out.println(shopId+"                     shopId");
        sku.setCommdityId(shopId);
        boolean flag=skuService.addSku(sku);
        return JSON.toJSONString(flag);
    }


    /**
     * 跳转到商品更新页面
     * @param id
     * @return
     */
    @RequestMapping("toUpdateShop")
    public String toUpdateShop(@RequestParam("id")Integer id,Model model ){

        System.out.println(id+"    id++++++++");
        //根据商品Id查询出商品信息
        Commodity comm=commodityService.getCommodityById(id);
        //从商品基本信息中获取限购基本信息Id
        Integer ticketInfoId=comm.getTicketInfoId();//购票信息Id
        //通过限购基本信息Id获取限购基本信息
        Ticketinginfo tt=ticketinginfoService.getTicketinginfoByTicketInfoId(ticketInfoId);
        model.addAttribute("comm",comm);
        model.addAttribute("ticketInfo",tt);
        return "updateShop";
    }


    /**
     * 判断商品是否可以删除，下架，上架
     * @param shopId
     * @return
     */
    @RequestMapping("isBoolDel")
    @ResponseBody
    public boolean isBooleDel(@RequestParam("shopId")Integer shopId,HttpServletRequest request) throws SQLException {

        boolean bb=true;
        Commodity comm=commodityService.getCommodityById(shopId);//获取本商品信息
        //这边判断能否删除和下架，上架，应该先判断登录的管理员身份
        //从session中获取当前登录用户信息
        Admin admin=(Admin)request.getSession().getAttribute("admin");//暂时用户没有存储，所以不能保存
        Integer lever=admin.getLevel();
       /* Integer lever=2;*/
        if(lever==0){//表示为超级管理员，可以随意删除，上下架
            bb=true;
        }else if(lever==1){//表示为省级代理，只要省级id匹配就可以删除，上下架，(场次表，根据代理商id查出省级id,与从商品中查出的省级id 匹配)

            List<Place> placeList=placeService.findByagentId(admin.getAdminId());///这是有后台用户存储信息的时候，用这个
          /*  List<Place> placeList=placeService.findByagentId(3);*/
            Integer provinceId=0;
            for(Place pp:placeList){
                provinceId=pp.getCityoneId();
                break;
            }
            if(comm.getProvinceId()==provinceId){
                bb=true;
            }else{
                bb=false;
            }

        }else if(lever==2){//表示为省级代理，必须省级id，市级id,都匹配才可以删除，上下架，
            List<Place> placeList=placeService.findByagentId(admin.getAdminId());
            Integer provinceId=0;
            Integer cityId=0;
            for(Place pp:placeList){
                provinceId=pp.getCityoneId();
                cityId=pp.getCitytwoId();
                break;
            }
            if(comm.getProvinceId()==provinceId&&comm.getCityId()==cityId){
                bb=true;
            }else{
                bb=false;
            }
        }

        return bb;
    }

    /**
     * 根据输入内容模糊查商品名返回集合
     * @param
     * @return
     */
    @RequestMapping("/findByCommdityLike")
    @ResponseBody
    public String findByCommdityLike(@Param("CommodityName")String CommodityName){

        System.out.println("======================CommodityName="+CommodityName);

        System.out.println(JSON.toJSONString(commodityService.findCommodityByCommodityNameLike(CommodityName),true));
        return JSON.toJSONString(commodityService.findCommodityByCommodityNameLike("%"+CommodityName+"%"),true);

    }

}